home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: 12 Mar 96 23:58:31 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.826675111@rscernix>
- References: <4htonk$350@news.hklink.net> <danpop.826488975@rscernix> <4i44vk$g16@rigel.rz.uni-ulm.de>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4i44vk$g16@rigel.rz.uni-ulm.de> peinel@faw.uni-ulm.de (Gertraud Peinel) writes:
-
- >In article <danpop.826488975@rscernix>, danpop@mail.cern.ch (Dan Pop) writes:
- >|>
- >|> You DON'T have to cast the value returned by malloc, casting it is actually
- >|> a BAD idea. But you DO have to include <stdlib.h> in any source file
- >|> which calls malloc.
- >
- >Hmmm, and what should I do with this (especially when I have to use these
- >compilers) ? :
- >
- > sun5:/users/peinel/clang(36)> uname -a
- > SunOS sun5 4.1.3 3 sun4c
- > sun5:/users/peinel/clang(35)> cat oh.c
- > #include <stdlib.h>
- >
- > typedef struct item {
- > int val;
- > struct item *next;
- > } ITEM, *PITEM;
- >
- > main()
- > {
- > PITEM head, current;
- > head= malloc(sizeof(ITEM));
- > head->val=1;
- > }
- > sun5:/users/peinel/clang(29)> cc oh.c
- > "oh.c", line 11: warning: illegal pointer combination
- > sun5:/users/peinel/clang(34)> which cc
- > /bin/cc
- > sun5:/users/peinel/clang(32)> CC oh.c
- > CC mist.c:
- > "oh.c", line 11: error: no standard conversion of char * to struct item *
- > "oh.c", line 10: warning: current not used
- > 1 error
- > sun5:/users/peinel/clang(33)> which CC
- > /com/owc++/bin/CC
- >
- >Without casting ?
-
- Neither of these compilers being a (standard) C compiler, the obvious
- answer is to get a C compiler. It makes absolutely no sense to expect
- standard C code to compile on a non-standard C compiler. BTW, have you
- tried the above code on a Fortran or Pascal compiler? They're almost as
- relevant to this code as the compilers you tried.
-
- If you have to use a K&R C compiler, write correct K&R C code.
- If you have to use a C++ compiler, write correct C++ code.
-
- It's a very poor idea to write C code which can be compiled by non-C
- compilers as well, because you cannot take advantage of the features which
- are unique to C, and you end up coding in a sort of C-- language :-)
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-